package h_10_22;

/**
 * 1423. 可获得的最大点数
 * https://leetcode.cn/problems/maximum-points-you-can-obtain-from-cards/
 */
public class Main2 {
    public int maxScore(int[] cardPoints, int k) {
        int n = cardPoints.length;
        int l = n - k;
        int s = 0;
        for(int i = 0;i < l;i++) {
            s += cardPoints[i];
        }

        int sum = s;
        int minSum = s;
        for(int i = l;i < n;i++) {
            sum += cardPoints[i];

            s += cardPoints[i] - cardPoints[i - l];

            minSum = Math.min(minSum,s);
        }

        return sum - minSum;
    }
}
